package com.fare.taluo.queue;

import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.foreveross.hbase.client.HbaseDriverManager;

import com.fare.taluo.db.hbase.HBaseCellModel;
import com.fare.taluo.db.hbase.HBaseRowModel;
import com.fare.taluo.util.StringUtils;

public class HbaseCrawl {
	
	public static void addRecord(String tableName, HBaseRowModel model)
            throws Exception{
    	HTableInterface table = null;
    	Put put = null;
        try {
        	if(StringUtils.isNotBlank(tableName) &&
        			model != null){
        	 	put = new Put(Bytes.toBytes(model.getRowkey()));
        	 	//循环将所有值都放入到put中
        		for(HBaseCellModel cell : model.getCells()){
        			if(StringUtils.isNotBlank(cell.getValue())){//写还是不写
        				put.add(Bytes.toBytes(cell.getFamily()),Bytes.toBytes(cell.getQualifier()), Bytes.toBytes(cell.getValue()));
        			}
        		}
	            
	            table = HbaseDriverManager.getHtable(tableName);
	            table.put(put);
        	}else{
        	}
        } finally{
        	HbaseDriverManager.releaseHtable(table);
        	table = null;
        	put = null;
        }
    }

	
}
